{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# pandas 库基本使用\n",
    "pandas 用来进行数据分析的第三方库,底层numpy matplotlib。\n",
    "官方文档 https://www.pypandas.cn/\n",
    "## pandas 安装\n",
    "`python -m pip install pandas`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 查看pandas版本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T05:53:42.307657Z",
     "start_time": "2020-10-24T05:53:40.879939Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.0.4'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#pandas导入\n",
    "import pandas as pd\n",
    "pd.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pandas导入csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T05:54:10.163319Z",
     "start_time": "2020-10-24T05:54:09.948442Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东西</td>\n",
       "      <td>灯市口</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>锡拉胡同21号院</td>\n",
       "      <td>101102647043</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>780.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>75.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南北</td>\n",
       "      <td>东单</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>东华门大街</td>\n",
       "      <td>101102650978</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>705.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南西</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>新世界中心</td>\n",
       "      <td>101102672743</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>210.0</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>兴隆都市馨园</td>\n",
       "      <td>101102577410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>420.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>39.0</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南</td>\n",
       "      <td>陶然亭</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>19</td>\n",
       "      <td>中海紫御公馆</td>\n",
       "      <td>101102574696</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>998.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23672</th>\n",
       "      <td>南北</td>\n",
       "      <td>广渠门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16</td>\n",
       "      <td>保利蔷薇</td>\n",
       "      <td>101102296423</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>1010.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>97.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23673</th>\n",
       "      <td>南北</td>\n",
       "      <td>永定门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>郭庄北里</td>\n",
       "      <td>101102593534</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>468.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>66.0</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23674</th>\n",
       "      <td>南北</td>\n",
       "      <td>和平里</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>康鸿家园</td>\n",
       "      <td>101102549465</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>155.0</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23675</th>\n",
       "      <td>南北</td>\n",
       "      <td>前门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>台基厂头条10号院</td>\n",
       "      <td>101102322422</td>\n",
       "      <td>4室1厅</td>\n",
       "      <td>1100.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>107.0</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23676</th>\n",
       "      <td>南北</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15</td>\n",
       "      <td>新景家园东区</td>\n",
       "      <td>101102657079</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>790.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>81.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>23677 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Direction District Elevator  Floor     Garden            Id Layout  \\\n",
       "0            东西      灯市口      NaN      6   锡拉胡同21号院  101102647043   3室1厅   \n",
       "1            南北       东单      无电梯      6      东华门大街  101102650978   2室1厅   \n",
       "2            南西      崇文门      有电梯     16      新世界中心  101102672743   3室1厅   \n",
       "3             南      崇文门      NaN      7     兴隆都市馨园  101102577410   1室1厅   \n",
       "4             南      陶然亭      有电梯     19     中海紫御公馆  101102574696   2室2厅   \n",
       "...         ...      ...      ...    ...        ...           ...    ...   \n",
       "23672        南北      广渠门      NaN     16       保利蔷薇  101102296423   2室1厅   \n",
       "23673        南北      永定门      NaN      6       郭庄北里  101102593534   2室1厅   \n",
       "23674        南北      和平里      NaN      6       康鸿家园  101102549465   3室2厅   \n",
       "23675        南北       前门      NaN      6  台基厂头条10号院  101102322422   4室1厅   \n",
       "23676        南北      崇文门      NaN     15     新景家园东区  101102657079   1室1厅   \n",
       "\n",
       "        Price Region Renovation   Size  Year  \n",
       "0       780.0     东城         精装   75.0  1988  \n",
       "1       705.0     东城         精装   60.0  1988  \n",
       "2      1400.0     东城         其他  210.0  1996  \n",
       "3       420.0     东城         精装   39.0  2004  \n",
       "4       998.0     东城         精装   90.0  2010  \n",
       "...       ...    ...        ...    ...   ...  \n",
       "23672  1010.0     东城         简装   97.0  2008  \n",
       "23673   468.0     东城         简装   66.0  1995  \n",
       "23674  1400.0     东城         简装  155.0  2000  \n",
       "23675  1100.0     东城         简装  107.0  1990  \n",
       "23676   790.0     东城         精装   81.0  2008  \n",
       "\n",
       "[23677 rows x 12 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lianjia = pd.read_csv('lianjia_t.csv')\n",
    "lianjia"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pandas常用语法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T05:58:50.228701Z",
     "start_time": "2020-10-24T05:58:50.222702Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(lianjia)\n",
    "# DataFrame 表格结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:00:22.409822Z",
     "start_time": "2020-10-24T06:00:22.401827Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=23677, step=1)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#索引\n",
    "lianjia.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:01:09.190547Z",
     "start_time": "2020-10-24T06:01:09.179552Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Direction', 'District', 'Elevator', 'Floor', 'Garden', 'Id', 'Layout',\n",
       "       'Price', 'Region', 'Renovation', 'Size', 'Year'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#列\n",
    "lianjia.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:02:20.269422Z",
     "start_time": "2020-10-24T06:02:20.261427Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(23677, 12)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#shape 元组格式数据: 几行几列的数据\n",
    "lianjia.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:03:30.456303Z",
     "start_time": "2020-10-24T06:03:30.448311Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#多少列数据\n",
    "lianjia.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:03:33.280874Z",
     "start_time": "2020-10-24T06:03:33.273877Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23677"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#you多少条数据\n",
    "lianjia.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:05:10.315885Z",
     "start_time": "2020-10-24T06:05:10.267912Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东西</td>\n",
       "      <td>灯市口</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>锡拉胡同21号院</td>\n",
       "      <td>101102647043</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>780.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>75.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南北</td>\n",
       "      <td>东单</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>东华门大街</td>\n",
       "      <td>101102650978</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>705.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南西</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>新世界中心</td>\n",
       "      <td>101102672743</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>210.0</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>兴隆都市馨园</td>\n",
       "      <td>101102577410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>420.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>39.0</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南</td>\n",
       "      <td>陶然亭</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>19</td>\n",
       "      <td>中海紫御公馆</td>\n",
       "      <td>101102574696</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>998.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>南北</td>\n",
       "      <td>广渠门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>18</td>\n",
       "      <td>幸福家园二期</td>\n",
       "      <td>101102407993</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>1180.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>111.0</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>南</td>\n",
       "      <td>西罗园</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>西革新里110号院</td>\n",
       "      <td>101102629841</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>319.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>42.0</td>\n",
       "      <td>1992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>南</td>\n",
       "      <td>西罗园</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>建予园</td>\n",
       "      <td>101102378003</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>640.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>105.0</td>\n",
       "      <td>1999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>南北</td>\n",
       "      <td>东花市</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>9</td>\n",
       "      <td>富贵园一区</td>\n",
       "      <td>101102345859</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1780.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>161.0</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>东北</td>\n",
       "      <td>东直门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>25</td>\n",
       "      <td>万国城MOMA</td>\n",
       "      <td>101102070529</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>1300.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>127.0</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>南</td>\n",
       "      <td>工体</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>5</td>\n",
       "      <td>十字坡东里</td>\n",
       "      <td>101102599410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>405.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>37.0</td>\n",
       "      <td>1986</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Direction District Elevator  Floor     Garden            Id Layout   Price  \\\n",
       "0         东西      灯市口      NaN      6   锡拉胡同21号院  101102647043   3室1厅   780.0   \n",
       "1         南北       东单      无电梯      6      东华门大街  101102650978   2室1厅   705.0   \n",
       "2         南西      崇文门      有电梯     16      新世界中心  101102672743   3室1厅  1400.0   \n",
       "3          南      崇文门      NaN      7     兴隆都市馨园  101102577410   1室1厅   420.0   \n",
       "4          南      陶然亭      有电梯     19     中海紫御公馆  101102574696   2室2厅   998.0   \n",
       "5         南北      广渠门      有电梯     18     幸福家园二期  101102407993   2室1厅  1180.0   \n",
       "6          南      西罗园      无电梯      6  西革新里110号院  101102629841   1室1厅   319.0   \n",
       "7          南      西罗园      有电梯     16        建予园  101102378003   2室1厅   640.0   \n",
       "8         南北      东花市      有电梯      9      富贵园一区  101102345859   3室2厅  1780.0   \n",
       "9         东北      东直门      有电梯     25    万国城MOMA  101102070529   2室2厅  1300.0   \n",
       "10         南       工体      无电梯      5      十字坡东里  101102599410   1室1厅   405.0   \n",
       "\n",
       "   Region Renovation   Size  Year  \n",
       "0      东城         精装   75.0  1988  \n",
       "1      东城         精装   60.0  1988  \n",
       "2      东城         其他  210.0  1996  \n",
       "3      东城         精装   39.0  2004  \n",
       "4      东城         精装   90.0  2010  \n",
       "5      东城         其他  111.0  2003  \n",
       "6      东城         其他   42.0  1992  \n",
       "7      东城         其他  105.0  1999  \n",
       "8      东城         精装  161.0  2003  \n",
       "9      东城         精装  127.0  2002  \n",
       "10     东城         精装   37.0  1986  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取得前5行数据\n",
    "lianjia.head(11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:04:30.013722Z",
     "start_time": "2020-10-24T06:04:29.980738Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23671</th>\n",
       "      <td>南北</td>\n",
       "      <td>和平里</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5</td>\n",
       "      <td>甘水桥</td>\n",
       "      <td>101102292212</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>565.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>56.0</td>\n",
       "      <td>1983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23672</th>\n",
       "      <td>南北</td>\n",
       "      <td>广渠门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>16</td>\n",
       "      <td>保利蔷薇</td>\n",
       "      <td>101102296423</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>1010.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>97.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23673</th>\n",
       "      <td>南北</td>\n",
       "      <td>永定门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>郭庄北里</td>\n",
       "      <td>101102593534</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>468.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>66.0</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23674</th>\n",
       "      <td>南北</td>\n",
       "      <td>和平里</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>康鸿家园</td>\n",
       "      <td>101102549465</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>155.0</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23675</th>\n",
       "      <td>南北</td>\n",
       "      <td>前门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>台基厂头条10号院</td>\n",
       "      <td>101102322422</td>\n",
       "      <td>4室1厅</td>\n",
       "      <td>1100.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>107.0</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23676</th>\n",
       "      <td>南北</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>15</td>\n",
       "      <td>新景家园东区</td>\n",
       "      <td>101102657079</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>790.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>81.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Direction District Elevator  Floor     Garden            Id Layout  \\\n",
       "23671        南北      和平里      NaN      5        甘水桥  101102292212   3室1厅   \n",
       "23672        南北      广渠门      NaN     16       保利蔷薇  101102296423   2室1厅   \n",
       "23673        南北      永定门      NaN      6       郭庄北里  101102593534   2室1厅   \n",
       "23674        南北      和平里      NaN      6       康鸿家园  101102549465   3室2厅   \n",
       "23675        南北       前门      NaN      6  台基厂头条10号院  101102322422   4室1厅   \n",
       "23676        南北      崇文门      NaN     15     新景家园东区  101102657079   1室1厅   \n",
       "\n",
       "        Price Region Renovation   Size  Year  \n",
       "23671   565.0     东城         简装   56.0  1983  \n",
       "23672  1010.0     东城         简装   97.0  2008  \n",
       "23673   468.0     东城         简装   66.0  1995  \n",
       "23674  1400.0     东城         简装  155.0  2000  \n",
       "23675  1100.0     东城         简装  107.0  1990  \n",
       "23676   790.0     东城         精装   81.0  2008  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#后六行\n",
    "lianjia.tail(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:05:00.222116Z",
     "start_time": "2020-10-24T06:05:00.210124Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Direction                南\n",
       "District                工体\n",
       "Elevator               无电梯\n",
       "Floor                    5\n",
       "Garden               十字坡东里\n",
       "Id            101102599410\n",
       "Layout                1室1厅\n",
       "Price                  405\n",
       "Region                  东城\n",
       "Renovation              精装\n",
       "Size                    37\n",
       "Year                  1986\n",
       "Name: 10, dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看第十一行的数据\n",
    "lianjia.loc[10] # 第11条数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:06:05.463660Z",
     "start_time": "2020-10-24T06:06:05.423682Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>南</td>\n",
       "      <td>工体</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>5</td>\n",
       "      <td>十字坡东里</td>\n",
       "      <td>101102599410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>405.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>37.0</td>\n",
       "      <td>1986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>南</td>\n",
       "      <td>地安门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>5</td>\n",
       "      <td>帽儿胡同45号院</td>\n",
       "      <td>101102516190</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>700.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>50.0</td>\n",
       "      <td>1985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>西</td>\n",
       "      <td>广渠门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>19</td>\n",
       "      <td>金桥国际</td>\n",
       "      <td>101102620368</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>462.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>54.0</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>西</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>18</td>\n",
       "      <td>太华公寓</td>\n",
       "      <td>101102624056</td>\n",
       "      <td>1室0厅</td>\n",
       "      <td>518.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>64.0</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>西南</td>\n",
       "      <td>菜户营</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>23</td>\n",
       "      <td>信德园</td>\n",
       "      <td>101102691675</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>960.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>其他</td>\n",
       "      <td>146.0</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>东</td>\n",
       "      <td>木樨地</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>4</td>\n",
       "      <td>西便门外大街</td>\n",
       "      <td>101102653830</td>\n",
       "      <td>2室0厅</td>\n",
       "      <td>457.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>简装</td>\n",
       "      <td>50.0</td>\n",
       "      <td>1957</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>西北</td>\n",
       "      <td>马甸</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18</td>\n",
       "      <td>双旗杆东里</td>\n",
       "      <td>101102570446</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>610.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>简装</td>\n",
       "      <td>58.0</td>\n",
       "      <td>1986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>北</td>\n",
       "      <td>马连道</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>18</td>\n",
       "      <td>第三区</td>\n",
       "      <td>101102583180</td>\n",
       "      <td>2房间2卫</td>\n",
       "      <td>340.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>精装</td>\n",
       "      <td>33.0</td>\n",
       "      <td>2011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>西南</td>\n",
       "      <td>六铺炕</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>17</td>\n",
       "      <td>六铺炕二区</td>\n",
       "      <td>101102306094</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>1120.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>其他</td>\n",
       "      <td>78.0</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>北</td>\n",
       "      <td>广安门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>26</td>\n",
       "      <td>荣丰2008</td>\n",
       "      <td>101101718499</td>\n",
       "      <td>1室0厅</td>\n",
       "      <td>320.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>精装</td>\n",
       "      <td>28.0</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>南北</td>\n",
       "      <td>牛街</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>12</td>\n",
       "      <td>平原里小区</td>\n",
       "      <td>101102532889</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>596.0</td>\n",
       "      <td>西城</td>\n",
       "      <td>简装</td>\n",
       "      <td>59.0</td>\n",
       "      <td>1999</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Direction District Elevator  Floor    Garden            Id Layout   Price  \\\n",
       "10         南       工体      无电梯      5     十字坡东里  101102599410   1室1厅   405.0   \n",
       "11         南      地安门      无电梯      5  帽儿胡同45号院  101102516190   2室1厅   700.0   \n",
       "12         西      广渠门      有电梯     19      金桥国际  101102620368   1室1厅   462.0   \n",
       "13         西      崇文门      有电梯     18      太华公寓  101102624056   1室0厅   518.0   \n",
       "14        西南      菜户营      有电梯     23       信德园  101102691675   3室1厅   960.0   \n",
       "15         东      木樨地      无电梯      4    西便门外大街  101102653830   2室0厅   457.0   \n",
       "16        西北       马甸      NaN     18     双旗杆东里  101102570446   2室1厅   610.0   \n",
       "17         北      马连道      有电梯     18       第三区  101102583180  2房间2卫   340.0   \n",
       "18        西南      六铺炕      有电梯     17     六铺炕二区  101102306094   3室1厅  1120.0   \n",
       "19         北      广安门      有电梯     26    荣丰2008  101101718499   1室0厅   320.0   \n",
       "20        南北       牛街      有电梯     12     平原里小区  101102532889   2室1厅   596.0   \n",
       "\n",
       "   Region Renovation   Size  Year  \n",
       "10     东城         精装   37.0  1986  \n",
       "11     东城         其他   50.0  1985  \n",
       "12     东城         精装   54.0  2004  \n",
       "13     东城         精装   64.0  2000  \n",
       "14     西城         其他  146.0  2002  \n",
       "15     西城         简装   50.0  1957  \n",
       "16     西城         简装   58.0  1986  \n",
       "17     西城         精装   33.0  2011  \n",
       "18     西城         其他   78.0  1990  \n",
       "19     西城         精装   28.0  2006  \n",
       "20     西城         简装   59.0  1999  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看区间范围的数据\n",
    "lianjia.loc[10:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:06:44.711159Z",
     "start_time": "2020-10-24T06:06:44.698180Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Direction', 'District', 'Elevator', 'Floor', 'Garden', 'Id', 'Layout',\n",
       "       'Price', 'Region', 'Renovation', 'Size', 'Year'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取所列的名字\n",
    "lianjia.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:07:22.715926Z",
     "start_time": "2020-10-24T06:07:22.703933Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('O')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#dtype 属性 : pandas里面数据类型\n",
    "lianjia.columns.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:10:49.274606Z",
     "start_time": "2020-10-24T06:10:49.259615Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10     405.0\n",
       "11     700.0\n",
       "12     462.0\n",
       "13     518.0\n",
       "14     960.0\n",
       "15     457.0\n",
       "16     610.0\n",
       "17     340.0\n",
       "18    1120.0\n",
       "19     320.0\n",
       "Name: Price, dtype: float64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取得某一列的数据\n",
    "lianjia['Price']\n",
    "lianjia['Price'][0:10]\n",
    "lianjia['Price'][10:20]\n",
    "# lianjia['Price'][-10:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:11:14.906548Z",
     "start_time": "2020-10-24T06:11:14.893556Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6000.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计分析\n",
    "## 最大值\n",
    "lianjia['Price'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:11:52.323208Z",
     "start_time": "2020-10-24T06:11:52.313213Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "60.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#最小值\n",
    "lianjia['Price'].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:12:39.380526Z",
     "start_time": "2020-10-24T06:12:39.365535Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "610.6683194661487"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#均值 : 算数平均值\n",
    "lianjia['Price'].mean() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:12:51.443503Z",
     "start_time": "2020-10-24T06:12:51.433507Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "610.6683194661487"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lianjia['Price'].sum()/lianjia['Price'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:13:20.928473Z",
     "start_time": "2020-10-24T06:13:20.915480Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14458793.8"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#总价\n",
    "lianjia['Price'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:13:24.547504Z",
     "start_time": "2020-10-24T06:13:24.536510Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23677"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数量统计\n",
    "lianjia['Price'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:13:30.530842Z",
     "start_time": "2020-10-24T06:13:30.519848Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "610.6683194661487"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算 算数平均\n",
    "lianjia['Price'].sum()/lianjia['Price'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:14:21.922549Z",
     "start_time": "2020-10-24T06:14:21.908563Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "499.0"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#中位数\n",
    "lianjia['Price'].median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:15:41.137294Z",
     "start_time": "2020-10-24T06:15:41.111306Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method DataFrame.isna of       Direction District Elevator  Floor     Garden            Id Layout  \\\n",
       "0            东西      灯市口      NaN      6   锡拉胡同21号院  101102647043   3室1厅   \n",
       "1            南北       东单      无电梯      6      东华门大街  101102650978   2室1厅   \n",
       "2            南西      崇文门      有电梯     16      新世界中心  101102672743   3室1厅   \n",
       "3             南      崇文门      NaN      7     兴隆都市馨园  101102577410   1室1厅   \n",
       "4             南      陶然亭      有电梯     19     中海紫御公馆  101102574696   2室2厅   \n",
       "...         ...      ...      ...    ...        ...           ...    ...   \n",
       "23672        南北      广渠门      NaN     16       保利蔷薇  101102296423   2室1厅   \n",
       "23673        南北      永定门      NaN      6       郭庄北里  101102593534   2室1厅   \n",
       "23674        南北      和平里      NaN      6       康鸿家园  101102549465   3室2厅   \n",
       "23675        南北       前门      NaN      6  台基厂头条10号院  101102322422   4室1厅   \n",
       "23676        南北      崇文门      NaN     15     新景家园东区  101102657079   1室1厅   \n",
       "\n",
       "        Price Region Renovation   Size  Year  \n",
       "0       780.0     东城         精装   75.0  1988  \n",
       "1       705.0     东城         精装   60.0  1988  \n",
       "2      1400.0     东城         其他  210.0  1996  \n",
       "3       420.0     东城         精装   39.0  2004  \n",
       "4       998.0     东城         精装   90.0  2010  \n",
       "...       ...    ...        ...    ...   ...  \n",
       "23672  1010.0     东城         简装   97.0  2008  \n",
       "23673   468.0     东城         简装   66.0  1995  \n",
       "23674  1400.0     东城         简装  155.0  2000  \n",
       "23675  1100.0     东城         简装  107.0  1990  \n",
       "23676   790.0     东城         精装   81.0  2008  \n",
       "\n",
       "[23677 rows x 12 columns]>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#NaN pandas种数据类型 代表缺失值\n",
    "lianjia.isna"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:17:44.728418Z",
     "start_time": "2020-10-24T06:17:44.621483Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东西</td>\n",
       "      <td>灯市口</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>锡拉胡同21号院</td>\n",
       "      <td>101102647043</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>780.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>75.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南北</td>\n",
       "      <td>东单</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>东华门大街</td>\n",
       "      <td>101102650978</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>705.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南西</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>新世界中心</td>\n",
       "      <td>101102672743</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>210.0</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>7</td>\n",
       "      <td>兴隆都市馨园</td>\n",
       "      <td>101102577410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>420.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>39.0</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南</td>\n",
       "      <td>陶然亭</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>19</td>\n",
       "      <td>中海紫御公馆</td>\n",
       "      <td>101102574696</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>998.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23672</th>\n",
       "      <td>南北</td>\n",
       "      <td>广渠门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>保利蔷薇</td>\n",
       "      <td>101102296423</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>1010.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>97.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23673</th>\n",
       "      <td>南北</td>\n",
       "      <td>永定门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>郭庄北里</td>\n",
       "      <td>101102593534</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>468.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>66.0</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23674</th>\n",
       "      <td>南北</td>\n",
       "      <td>和平里</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>康鸿家园</td>\n",
       "      <td>101102549465</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>155.0</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23675</th>\n",
       "      <td>南北</td>\n",
       "      <td>前门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>台基厂头条10号院</td>\n",
       "      <td>101102322422</td>\n",
       "      <td>4室1厅</td>\n",
       "      <td>1100.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>107.0</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23676</th>\n",
       "      <td>南北</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>15</td>\n",
       "      <td>新景家园东区</td>\n",
       "      <td>101102657079</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>790.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>81.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>23677 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Direction District Elevator  Floor     Garden            Id Layout  \\\n",
       "0            东西      灯市口      无电梯      6   锡拉胡同21号院  101102647043   3室1厅   \n",
       "1            南北       东单      无电梯      6      东华门大街  101102650978   2室1厅   \n",
       "2            南西      崇文门      有电梯     16      新世界中心  101102672743   3室1厅   \n",
       "3             南      崇文门      无电梯      7     兴隆都市馨园  101102577410   1室1厅   \n",
       "4             南      陶然亭      有电梯     19     中海紫御公馆  101102574696   2室2厅   \n",
       "...         ...      ...      ...    ...        ...           ...    ...   \n",
       "23672        南北      广渠门      无电梯     16       保利蔷薇  101102296423   2室1厅   \n",
       "23673        南北      永定门      无电梯      6       郭庄北里  101102593534   2室1厅   \n",
       "23674        南北      和平里      无电梯      6       康鸿家园  101102549465   3室2厅   \n",
       "23675        南北       前门      无电梯      6  台基厂头条10号院  101102322422   4室1厅   \n",
       "23676        南北      崇文门      无电梯     15     新景家园东区  101102657079   1室1厅   \n",
       "\n",
       "        Price Region Renovation   Size  Year  \n",
       "0       780.0     东城         精装   75.0  1988  \n",
       "1       705.0     东城         精装   60.0  1988  \n",
       "2      1400.0     东城         其他  210.0  1996  \n",
       "3       420.0     东城         精装   39.0  2004  \n",
       "4       998.0     东城         精装   90.0  2010  \n",
       "...       ...    ...        ...    ...   ...  \n",
       "23672  1010.0     东城         简装   97.0  2008  \n",
       "23673   468.0     东城         简装   66.0  1995  \n",
       "23674  1400.0     东城         简装  155.0  2000  \n",
       "23675  1100.0     东城         简装  107.0  1990  \n",
       "23676   790.0     东城         精装   81.0  2008  \n",
       "\n",
       "[23677 rows x 12 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#处理缺失值\n",
    "# 1. 用特定值代替 缺失值 \n",
    "lianjia.fillna('无电梯')\n",
    "# lianjia.head(6).fillna('无电梯')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:23:59.793254Z",
     "start_time": "2020-10-24T06:23:59.715301Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东西</td>\n",
       "      <td>灯市口</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>锡拉胡同21号院</td>\n",
       "      <td>101102647043</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>780.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>75.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南北</td>\n",
       "      <td>东单</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>东华门大街</td>\n",
       "      <td>101102650978</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>705.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南西</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>新世界中心</td>\n",
       "      <td>101102672743</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>210.0</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>7</td>\n",
       "      <td>兴隆都市馨园</td>\n",
       "      <td>101102577410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>420.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>39.0</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南</td>\n",
       "      <td>陶然亭</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>19</td>\n",
       "      <td>中海紫御公馆</td>\n",
       "      <td>101102574696</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>998.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23672</th>\n",
       "      <td>南北</td>\n",
       "      <td>广渠门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>保利蔷薇</td>\n",
       "      <td>101102296423</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>1010.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>97.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23673</th>\n",
       "      <td>南北</td>\n",
       "      <td>永定门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>郭庄北里</td>\n",
       "      <td>101102593534</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>468.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>66.0</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23674</th>\n",
       "      <td>南北</td>\n",
       "      <td>和平里</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>康鸿家园</td>\n",
       "      <td>101102549465</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>155.0</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23675</th>\n",
       "      <td>南北</td>\n",
       "      <td>前门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>台基厂头条10号院</td>\n",
       "      <td>101102322422</td>\n",
       "      <td>4室1厅</td>\n",
       "      <td>1100.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>简装</td>\n",
       "      <td>107.0</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23676</th>\n",
       "      <td>南北</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>15</td>\n",
       "      <td>新景家园东区</td>\n",
       "      <td>101102657079</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>790.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>81.0</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>23677 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Direction District Elevator  Floor     Garden            Id Layout  \\\n",
       "0            东西      灯市口      无电梯      6   锡拉胡同21号院  101102647043   3室1厅   \n",
       "1            南北       东单      无电梯      6      东华门大街  101102650978   2室1厅   \n",
       "2            南西      崇文门      有电梯     16      新世界中心  101102672743   3室1厅   \n",
       "3             南      崇文门      无电梯      7     兴隆都市馨园  101102577410   1室1厅   \n",
       "4             南      陶然亭      有电梯     19     中海紫御公馆  101102574696   2室2厅   \n",
       "...         ...      ...      ...    ...        ...           ...    ...   \n",
       "23672        南北      广渠门      无电梯     16       保利蔷薇  101102296423   2室1厅   \n",
       "23673        南北      永定门      无电梯      6       郭庄北里  101102593534   2室1厅   \n",
       "23674        南北      和平里      无电梯      6       康鸿家园  101102549465   3室2厅   \n",
       "23675        南北       前门      无电梯      6  台基厂头条10号院  101102322422   4室1厅   \n",
       "23676        南北      崇文门      无电梯     15     新景家园东区  101102657079   1室1厅   \n",
       "\n",
       "        Price Region Renovation   Size  Year  \n",
       "0       780.0     东城         精装   75.0  1988  \n",
       "1       705.0     东城         精装   60.0  1988  \n",
       "2      1400.0     东城         其他  210.0  1996  \n",
       "3       420.0     东城         精装   39.0  2004  \n",
       "4       998.0     东城         精装   90.0  2010  \n",
       "...       ...    ...        ...    ...   ...  \n",
       "23672  1010.0     东城         简装   97.0  2008  \n",
       "23673   468.0     东城         简装   66.0  1995  \n",
       "23674  1400.0     东城         简装  155.0  2000  \n",
       "23675  1100.0     东城         简装  107.0  1990  \n",
       "23676   790.0     东城         精装   81.0  2008  \n",
       "\n",
       "[23677 rows x 12 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = lianjia.fillna('无电梯')\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:33:22.642520Z",
     "start_time": "2020-10-24T06:33:22.614536Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Elevator</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>无电梯</th>\n",
       "      <td>14315</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>有电梯</th>\n",
       "      <td>9342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>精装</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>毛坯</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>简装</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Price\n",
       "Elevator       \n",
       "无电梯       14315\n",
       "有电梯        9342\n",
       "精装           11\n",
       "毛坯            7\n",
       "简装            2"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### 数据分组\n",
    "t[['Elevator','Price']].groupby('Elevator').count().sort_values(by='Price',ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:26:49.726283Z",
     "start_time": "2020-10-24T06:26:49.655323Z"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
